var $parentNode = window.parent.document;

function $childNode(name) {
    return window.frames[name]
}

// tooltips
$('.tooltip-demo').tooltip({
    selector: "[data-toggle=tooltip]",
    container: "body"
});

// 使用animation.css修改Bootstrap Modal
$('.modal').appendTo("body");

$("[data-toggle=popover]").popover();

//折叠ibox
$('.collapse-link').click(function () {
    var ibox = $(this).closest('div.ibox');
    var button = $(this).find('i');
    var content = ibox.find('div.ibox-content');
    content.slideToggle(200);
    button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
    ibox.toggleClass('').toggleClass('border-bottom');
    setTimeout(function () {
        ibox.resize();
        ibox.find('[id^=map-]').resize();
    }, 50);
});

//关闭ibox
$('.close-link').click(function () {
    var content = $(this).closest('div.ibox');
    content.remove();
});

//判断当前页面是否在iframe中
if (top == this) {
    var gohome = '<div class="gohome"><a class="animated bounceInUp" href="device_board.html?v=4.0" title="返回首页"><i class="fa fa-home"></i></a></div>';
    $('body').append(gohome);
}

//animation.css
function animationHover(element, animation) {
    element = $(element);
    element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //动画完成之前移除class
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
}

//拖动面板
function WinMove() {
    var element = "[class*=col]";
    var handle = ".ibox-title";
    var connect = "[class*=col]";
    $(element).sortable({
        handle: handle,
        connectWith: connect,
        tolerance: 'pointer',
        forcePlaceholderSize: true,
        opacity: 0.8,
    })
        .disableSelection();
}

// 清空查询
clearSearch();

function clearSearch() {

    if ($('*[clearable]').is('input')) {
        $('*[clearable]').parent().addClass("clearSearch");
        $(".clearSearch").append("<i class=\"fa clearSearchIcon\" style=\"font-size: 16px;font-weight: bold\">×</i>");
        $(".clearSearchIcon").click(function () {
            $(this).siblings("input").val("");
            //$('#dataTable').bootstrapTable('refresh');
            querySearch();
        })
    }
    if ($('*[clearable]').is('select')) {
        setTimeout(function () {
            $('*[clearable]').siblings("button").addClass("clearSearchSelect");
            $(".clearSearchSelect").append("<i class=\"fa clearSearchIcon\" style=\"font-size: 16px;font-weight: bold\">×</i>");
            $('*[clearable]').change(function () {
                if ($(this).siblings(".dropdown-menu.open").children("ul").children("li").hasClass("selected")) {
                    $(this).siblings("button").children(".clearSearchIcon").addClass("selected");
                    $(this).siblings("button").children(".clearSearchIcon").siblings(".bs-caret").addClass("bs-caret-none");
                } else {
                    $(this).siblings("button").children(".clearSearchIcon").removeClass("selected");
                    $(this).siblings("button").children(".clearSearchIcon").siblings(".bs-caret").removeClass("bs-caret-none");
                }
            });
            $(".clearSearchIcon").click(function () {
                $(this).parent().siblings("select").val("");
                $(this).parent().siblings("select").selectpicker('refresh');
                //$('#dataTable').bootstrapTable('refresh');
                querySearch();
                $(this).removeClass("selected");
                $(this).siblings(".bs-caret").removeClass("bs-caret-none");
            })
        }, 2000)

    }

}

// 清空查询 end

// 去掉所有input的autocomplete, 显示指定的除外
autocompleteOff();

function autocompleteOff() {
    $('input:not([autocomplete]),textarea:not([autocomplete]),select:not([autocomplete])').attr('autocomplete', 'off');
}

// 去掉所有input的autocomplete, 显示指定的除外 end

// 内页左侧布局
uiLayout();

function uiLayout() {
    if (!$(".ui-layout-west").hasClass("ui-layout-west-right")) {
        $(".ui-layout-center").css("margin-left", "calc(230px + 8px)");
        $(".ui-layout-toggler").click(function () {
            if ($(".content-open").is(':visible')) {
                $(".ui-layout-west").css("display", "none");
                $(".ui-layout-center").css("margin-left", "8px");

                $(".content-open").css("display", "none");
                $(".content-closed").css("display", "block");
                $(".ui-layout-resizer").removeClass("ui-layout-resizer-open");
            } else {
                $(".ui-layout-west").css("display", "block");
                $(".ui-layout-center").css("margin-left", "calc(230px + 8px)");

                $(".content-open").css("display", "block");
                $(".content-closed").css("display", "none");
                $(".ui-layout-resizer").addClass("ui-layout-resizer-open");
            }
        });
    } else {
        /*内页右侧布局*/
        $(".ui-layout-center").css("margin-right", "238px");
        $(".ui-layout-resizer").addClass("ui-layout-resizer-open-right").removeClass("ui-layout-resizer-open");
        $(".ui-layout-center").addClass("ui-layout-center-noy");
        $(".ui-layout-toggler").click(function () {
            if ($(".content-open").is(':visible')) {
                $(".ui-layout-west").css("display", "none");
                $(".ui-layout-center").css("margin-right", "8px");

                $(".content-open").css("display", "none");
                $(".content-closed").css("display", "block");
                $(".ui-layout-resizer").removeClass("ui-layout-resizer-open-right").addClass("ui-layout-resizer-right");
            } else {
                $(".ui-layout-west").css("display", "block");
                $(".ui-layout-center").css("margin-right", "238px");

                $(".content-open").css("display", "block");
                $(".content-closed").css("display", "none");
                $(".ui-layout-resizer").addClass("ui-layout-resizer-open-right").removeClass("ui-layout-resizer-right");
            }
        });
        /*内页右侧布局 end*/
    }

    $(".ui-layout-west").parent("body").css("overflow", "hidden");
    /*获取高度，赋值给ui-layout-content，解决overflow不能使用*/
    var winHeight = $(window).height();
    if ($(".ui-layout-west .box-main .operation").length) {
        $(".ui-layout-content").css("height", winHeight - 39 - 42);
        $(window).resize(function () {
            winHeight = $(window).height();
            $(".ui-layout-content").css("height", winHeight - 39 - 42);
        });
    } else {
        $(".ui-layout-content").css("height", winHeight - 50);
        $(window).resize(function () {
            winHeight = $(window).height();
            $(".ui-layout-content").css("height", winHeight - 50);
        });
    }

}


// 内页左侧布局 end

// 内页顶部状态切换查询
$(".switchTop button").click(function () {
    $(this).addClass("activeSelect");
    $(this).siblings("button").removeClass("activeSelect");
});

// 内页顶部状态切换查询 end


//modal弹窗点击遮罩层不关闭
$(function () {
    $('.modal.inmodal.fade').modal({
        backdrop: 'static',//点击遮罩层不会被关闭
        show: false
    })
    //可点击esc关闭
    $('.modal.inmodal.fade').attr('tabindex', -1)
})
//modal弹窗点击遮罩层不关闭

//每个页面body加主题class
$("body").addClass("skin-purple");
//每个页面body加主题class end